import { query, update } from '@/api/dict'

const dict = {
  state: {
    options: {}
  },

  mutations: {
    SET_OPTIONS: (state, options) => {
      state.options = options
    }
  },

  actions: {
    // 获取用户信息
    GetOptions({ commit }) {
      return new Promise((resolve, reject) => {
        query().then(response => {
          const data = response.data
          commit('SET_OPTIONS', data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    UpdateOptions({ commit }, data) {
      return new Promise((resolve, reject) => {
        update(data.data).then(response => {
          commit('SET_OPTIONS', data)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default dict
